//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.wyh.controller.groupfour.proprietor;

import com.wyh.common.result.Result;
import com.wyh.domain.dto.groupfour.customerDTO.ContactsDTO;
import com.wyh.domain.vo.gruopfour.customerVO.ContactsVO;
import com.wyh.service.appservice.ContactsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(
        tags = {"联系人"}
)
@RestController
@RequestMapping({"/contacts"})

public class ContactController {
    private final ContactsService contactsService;

    @Autowired
    public ContactController(ContactsService contactsService) {
        this.contactsService = contactsService;
    }

    @GetMapping({"/custmer/{customerId}"})
    @ApiOperation("查询联系人信息")
    public Result<List<ContactsVO>> getContactsByCustomerId(@PathVariable
                                                               @ApiParam(value = "客户id",required = true) int customerId,
                                                            @RequestParam(value = "页码",defaultValue = "1") Integer pageNum,
                                                            @RequestParam(value = "条数",defaultValue = "10") Integer pageSize) {
        List<ContactsVO> myTickets = this.contactsService.findContactsByCustomerId(customerId, pageNum, pageSize);
        return Result.success(myTickets);
    }

    @GetMapping({"/DeleteContact/{id}"})
    @ApiOperation("删除联系人信息")
    public Result<String> deleteContactsById(@PathVariable
                                                 @ApiParam(value = "联系人id",required = true) int id) {
        this.contactsService.deleteContacts(id);
        return Result.success();
    }

    @PostMapping({"addContact"})
    @ApiOperation("添加联系人")
    public Result addContacts(@RequestBody
                                           @ApiParam(value = "联系人信息",required = true)
                                            @Validated ContactsDTO contactsDTO) {
        Integer rows = this.contactsService.addContacts(contactsDTO);
        if (rows!=0) {
            return Result.success();
        }
        return Result.error();
    }
}
